var api = require('../../../utils/api.js')
var $ = require('../../../utils/util.js')
var regeneratorRuntime = require('../../../utils/runtime.js')
var app = getApp()

Page({
  data: {

    hasMore: true, // 判断 数据是否全部加载完
    isLodingLock: true, //锁 防止数据加载
    pageList: [], //分页数据列表
    pageNum: 1, //页码
    isShowKong: false, // 是否是空
    keyword: '', // 搜索关键字

    currentTab: 0, // 当前选中的tab
    nav: [{
        name: '待检修',
        type: 0,
        num: 0,
        color: '#dd524d',
        icon: 'icon-completed'
      },
      {
        name: '检修中',
        type: 1,
        num: 0,
        color: '#16304f',
        icon: 'icon-gengduo'
      },
      {
        name: '已检修',
        type: 2,
        num: 0,
        color: '#50850a',
        icon: 'icon-tick'
      }
    ], // tab 
  },

  onLoad: function (options) {
    //this.getPagServer(1, true) //获取分页数据  
    app._total({
      type: 6,
      is_all: 1
    }).then((res) => {
      var nav = this.data.nav
      nav[0].num = res.data.un_deal
      nav[1].num = res.data.to_deal
      nav[2].num = res.data.all_deal
      this.setData({
        nav
      })
    })
  },
  onShow: function () {
    this.getPagServer(1, true) //获取分页数据  
    app._total({
      type: 6,
      is_all: 1
    }).then((res) => {
      var nav = this.data.nav
      nav[0].num = res.data.un_deal
      nav[1].num = res.data.to_deal
      nav[2].num = res.data.all_deal
      this.setData({
        nav
      })
    })
  },

  onReachBottom() { //滑动到底部触发
    this.loadingMore()
  },
  onPullDownRefresh: function () { // 下拉刷新
    this.getPagServer(1, true) //获取分页数据
  },


  loadingMore: function () { // 加载更多
    console.log(this.data.isLodingLock, 111)
    if (this.data.isLodingLock) {
      this.setData({
        isLodingLock: false
      })
      this.getPagServer()
    }
  },

  getPagServer(pageNum, isClickTab = false) { //分页  
    console.log('=====================================');
    console.log(this.data.pageNum);
    var params = {
      pageNum: pageNum == 1 ? 1 : this.data.pageNum,
      pageSize: 10,
      type: this.data.nav[this.data.currentTab].type,
      keyword: this.data.keyword
    }
    $.getPageList(api, this, api.checkManage.getList, params, isClickTab).then((res) => {
      wx.stopPullDownRefresh() // 接口数据请求完停止刷新
    })
  },

  //##input 输入##
  input_handle(e) {
    this.setData({
      [e.currentTarget.dataset.key]: e.detail.value
    })
  },
  //##input 输入##

  keywordConfirmHandle() { // 搜索输入框 
    // if ($.isNull(this.data.keyword)) {
      // $.toast('请输入内容')
    // } else {
      this.getPagServer(1, true) //获取分页数据
    // }

  },

  tabHanlde(e) {
    var {
      index
    } = e.detail
    this.setData({
      currentTab: index
    })
    this.getPagServer(1, true) //获取分页数据
  },

  toCheckManageMsgHandel(e) { // 去详情
    var {
      item
    } = $.detail(e)
    $.linkurl(`/pages/checkManage/checkManageMsg/checkManageMsg?check_id=${item.check_id}&station_id=${item.station_id}&ticket_num=${item.ticket_num}`)
  }


})